home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / nihcl-30.lha / nihcl-3.0 / lib / Float.c < prev    next >
C/C++ Source or Header  |  1990-05-19  |  2KB  |  103 lines

  1. /* Float.c -- implementation of Float object
  2.  
  3.     THIS SOFTWARE FITS THE DESCRIPTION IN THE U.S. COPYRIGHT ACT OF A
  4.     "UNITED STATES GOVERNMENT WORK".  IT WAS WRITTEN AS A PART OF THE
  5.     AUTHOR'S OFFICIAL DUTIES AS A GOVERNMENT EMPLOYEE.  THIS MEANS IT
  6.     CANNOT BE COPYRIGHTED.  THIS SOFTWARE IS FREELY AVAILABLE TO THE
  7.     PUBLIC FOR USE WITHOUT A COPYRIGHT NOTICE, AND THERE ARE NO
  8.     RESTRICTIONS ON ITS USE, NOW OR SUBSEQUENTLY.
  9.  
  10. Author:
  11.     K. E. Gorlen
  12.     Bg. 12A, Rm. 2033
  13.     Computer Systems Laboratory
  14.     Division of Computer Research and Technology
  15.     National Institutes of Health
  16.     Bethesda, Maryland 20892
  17.     Phone: (301) 496-1111
  18.     uucp: uunet!nih-csl!kgorlen
  19.     Internet: kgorlen@alw.nih.gov
  20.     December, 1985
  21.  
  22. Function:
  23.     
  24. Provides an object that contains a double.
  25.  
  26. $Log:    Float.c,v $
  27.  * Revision 3.0  90/05/20  00:19:36  kgorlen
  28.  * Release for 1st edition.
  29.  * 
  30. */
  31.  
  32. #include "Float.h"
  33. #include "nihclIO.h"
  34.  
  35. #define    THIS    Float
  36. #define    BASE    Object
  37. #define BASE_CLASSES BASE::desc()
  38. #define MEMBER_CLASSES
  39. #define VIRTUAL_BASE_CLASSES Object::desc()
  40.  
  41. DEFINE_CLASS(Float,1,"$Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/lib/RCS/Float.c,v 3.0 90/05/20 00:19:36 kgorlen Rel $",NULL,NULL);
  42.  
  43. Float::Float(istream& strm)    { parseFloat(strm); }
  44.  
  45. int Float::compare(const Object& ob) const
  46. {
  47.     assertArgSpecies(ob,classDesc,"compare");
  48.     register double t = val-castdown(ob).val;
  49.     if (t < 0) return -1;
  50.     if (t > 0) return 1;
  51.     return 0;
  52. }
  53.  
  54. void Float::deepenShallowCopy()    {}
  55.  
  56. unsigned Float::hash() const
  57. {
  58.     union {
  59.         unsigned asint[2];
  60.         double asdouble;
  61.     };
  62.     asdouble = val;
  63.     return asint[0] ^ asint[1];
  64. }
  65.  
  66. bool Float::isEqual(const Object& ob) const
  67. {
  68.     return ob.isSpecies(classDesc) && val==castdown(ob).val;
  69. }
  70.  
  71. const Class* Float::species() const { return &classDesc; }
  72.  
  73. void Float::printOn(ostream& strm) const
  74. {
  75.     strm << val;
  76. }
  77.  
  78. void Float::scanFrom(istream& strm)    { parseFloat(strm); }
  79.  
  80. Float::Float(OIOin& strm)
  81.     : BASE(strm)
  82. {
  83.     strm >> val;
  84. }
  85.  
  86. void Float::storer(OIOout& strm) const
  87. {
  88.     BASE::storer(strm);
  89.     strm << val;
  90. }
  91.  
  92. Float::Float(OIOifd& fd)
  93.     : BASE(fd)
  94. {
  95.     fd >> val;
  96. }
  97.  
  98. void Float::storer(OIOofd& fd) const
  99. {
  100.     BASE::storer(fd);
  101.     fd << val;
  102. }
  103.